package framework;

import java.util.Hashtable;

public enum Controls {
	UP_P1, UP_P2, DOWN_P1, DOWN_P2, LEFT_P1, LEFT_P2, RIGHT_P1, RIGHT_P2,
	PARRY_P1, PARRY_P2, START_P1, START_P2, A_P1, 
	A_P2, B_P1, B_P2, X_P1, X_P2, Y_P1, Y_P2, TELEPORT_P1, TELEPORT_P2;
	
	private static Hashtable<String, Controls> matching = new Hashtable<>();
	static {
		matching.put("UP_P1", UP_P1);
		matching.put("UP_P2", UP_P2);
		matching.put("DOWN_P1", DOWN_P1);
		matching.put("DOWN_P2", DOWN_P2);
		matching.put("LEFT_P1", LEFT_P1);
		matching.put("LEFT_P2", LEFT_P2);
		matching.put("RIGHT_P1", RIGHT_P1);
		matching.put("RIGHT_P2", RIGHT_P2);
		matching.put("PARRY_P1", PARRY_P1);
		matching.put("PARRY_P2", PARRY_P2);
		matching.put("START_P1", START_P1);
		matching.put("START_P2", START_P2);
		matching.put("A_P1", A_P1);
		matching.put("A_P2", A_P2);
		matching.put("B_P1", B_P1);
		matching.put("B_P2", B_P2);
		matching.put("X_P1", X_P1);
		matching.put("X_P2", X_P2);
		matching.put("Y_P1", Y_P1);
		matching.put("Y_P2", Y_P2);
		matching.put("TELEPORT_P1", TELEPORT_P1);
		matching.put("TELEPORT_P2", TELEPORT_P2);
	}
	
	/**
	 * 
	 * @param c
	 * @return -1 if none of the players
	 *         1 if player 1 
	 *         2 if player 2
	 */
	public static int getPlayer(Controls c) {
		int player = -1;
		if (c == PARRY_P1 || c == START_P1 || c == A_P1 || c == B_P1 || c == TELEPORT_P1 ||
		    c == X_P1 || c == Y_P1 || c == UP_P1 || c == DOWN_P1 || c == LEFT_P1 || c == RIGHT_P1) {
			player = 1;
		} else if(c == PARRY_P2 || c == START_P2 || c == A_P2 || c == B_P2 || c == TELEPORT_P2 || 
			    c == X_P2 || c == Y_P2 || c == UP_P2 || c == DOWN_P2 || c == LEFT_P2 || c == RIGHT_P2) {
			player = 2;
		}
		return player;		
	}
	
	/**
	 * 
	 * @param c
	 * @return -1 if none of the players
	 *         1 if player 1 
	 *         2 if player 2
	 */
	public static Controls getControls(String string) {
	    return matching.get(string);
	}
}
